<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>论坛板块</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form :model="editForm" label-width="100px" :rules="editFormRules" ref="editForm">
          <el-row>
            <el-col :span="16">
              <el-form-item label="板块名称:" prop="name">
                <el-input v-model="editForm.name" auto-complete="off" placeholder="板块名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="16">
              <el-form-item label="版主:" prop="user_id">
                <div style="display: flex">
                  <span v-if="applyBox" class="mr-10">{{ applyBox.realname }}</span>
                  <el-button size="small" @click="showDevice(1)">选择版主</el-button>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="8">
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="16">
              <el-form-item label="文章审核人:" prop="examine_user">
                <div style="display: flex">
                  <span v-if="applyBoxexmation" class="mr-10">{{ applyBoxexmation.realname }}</span>
                  <el-button size="small" @click="showDevice(2)">选择审核人</el-button>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="8">
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="16">
              <el-form-item label="版块简介:" prop="description">
                <el-input v-model="editForm.description" auto-complete="off" placeholder="填写版块简介"
                          type="textarea"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="submitFormAdd">确定修改</el-button>
      </div>
    </div>
    <singleTeacherModle :visible.sync="deviceVisible" @studentFn="initFile"
                        :dynamicTagsArray="dynamicTagsArray"></singleTeacherModle>
  </div>
</template>

<script>
export default {
  props: ['visible', 'forumId'],
  components: {},
  data() {
    return {
      dialogVisible: false,
      editForm: {
        name: '',
        user_id: '',
        description: '',
        examine_user: ''
      },
      usertype: '0',
      dilogType: 1,
      deviceVisible: false,
      // 编辑界面数据
      editFormRules: {
        name: [
          {required: true, message: '请填写版块名称', trigger: 'blur'}
        ],
        user_id: [
          {required: true, message: '请选择版主', trigger: 'blur'}
        ],
        examine_user: [
          {required: true, message: '请选择审核人', trigger: 'blur'}
        ]
      },
      dynamicTagsArray: {},
      applyBoxexmation: null,
      applyBox: null,
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if (this.forumId) {
          this.InitFn()
        }
      } else {
        this.editForm = {
          name: '',
          user_id: '',
          description: '',
          examine_user: ''
        }
        this.applyBoxexmation = null
        this.applyBox = null
      }
    }
  },
  created() {

  },
  methods: {
    InitFn() {
      this.$fetch(this.api.forum_plate_edit, {
        id: this.forumId
      }).then((response) => {
        if (response.code === 0) {
          this.editForm.name = response.vo.name
          this.editForm.description = response.vo.description
          this.editForm.user_id = response.vo.user_id
          this.applyBox = response.vo.user
          this.applyBoxexmation = response.vo.examine
          this.editForm.examine_user = response.vo.examine_user
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    checkEditFn() {
      if (!this.infoForm[this.itemlable]) {
        this.$message.error('请填写信息');
        return
      }
      this.$emit('checkList', {name: this.itemlable, val: this.infoForm[this.itemlable]})
      this.closePOpup()
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    submitFormAdd() {
      let url = this.api.forum_plate_add
      if (this.forumId) {
        url = this.api.forum_plate_edit
        this.editForm.id = this.forumId
      }
      this.$post(url, this.editForm).then((response) => {
        if (response.code === 0) {
          this.$message({
            message: '编辑成功',
            type: 'success'
          })
          this.$emit('InitFn')
          this.closePOpup()
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    showDevice(option) {
      this.dilogType = option
      this.deviceVisible = !this.deviceVisible
    },
    initFile(option) {
      if (this.dilogType === 1) {
        this.applyBox = option
        this.editForm.user_id = option.id
      } else {
        this.applyBoxexmation = option
        this.editForm.examine_user = option.id
      }
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 600px;
  height: 500px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


